<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta http-equiv="Content-Style-Type" content="text/css">
<link rel="up" title="FatFs" href="../00index_e.html">
<link rel="alternate" hreflang="ja" title="Japanese" href="../ja/fdisk.html">
<link rel="stylesheet" href="../css_e.css" type="text/css" media="screen" title="ELM Default">
<title>FatFs - f_fdisk</title>
</head>

<body>

<div class="para func">
<h2>f_fdisk</h2>
<p>The f_fdisk fucntion divides a physical drive.</p>
<pre>
FRESULT f_fdisk (
  BYTE  <span class="arg">pdrv</span>,         <span class="c">/* [IN] Physical drive number */</span>
  const LBA_t <span class="arg">ptbl[]</span>, <span class="c">/* [IN] Partition map table */</span>
  void* <span class="arg">work</span>          <span class="c">/* [IN] Work area */</span>
);
</pre>
</div>

<div class="para arg">
<h4>Parameters</h4>
<dl class="par">
<dt>pdrv</dt>
<dd>Specifies the <em>physical drive</em> to be divided. This is not the logical drive number but the drive identifier passed to the low level disk functions.</dd>
<dt>ptbl</dt>
<dd>List of partitions to create on the drive. The data type <tt>LBA_t</tt> is alias of <tt>DWORD</tt> or <tt>QWORD</tt> depends on the configuration option <tt><a href="config.html#fs_lba64">FF_LBA64</a></tt>.</dd>
<dt>work</dt>
<dd>Pointer to the function work area. The size must be at least <tt><a href="config.html#max_ss">FF_MAX_SS</a></tt> bytes. When a null pointer is given with <tt><a href="config.html#use_lfn">FF_USE_LFN</a> = 3</tt>, a memory block is obtained in this function for the working buffer.</dd>
</dl>
</div>

<div class="para ret">
<h4>Return Values</h4>
<p>
<a href="rc.html#ok">FR_OK</a>,
<a href="rc.html#de">FR_DISK_ERR</a>,
<a href="rc.html#nr">FR_NOT_READY</a>,
<a href="rc.html#wp">FR_WRITE_PROTECTED</a>,
<a href="rc.html#ip">FR_INVALID_PARAMETER</a>,
<a href="rc.html#nc">FR_NOT_ENOUGH_CORE</a>
</p>
</div>

<div class="para desc">
<h4>Description</h4>
<p>The <tt>f_fdisk</tt> function creates partitions on the physical drive. The partitioning format can be in generic MBR or GPT. The partition map table specifies how to divide the physical drive. The first item specifies the size of the first partition and the partitions are located on the drive in order of from the first item. When the value of item is less than or equal to 100, it specifies the partition size in percentage of the entire drive space. When it is larger than 100, it specifies number of sectors. The partition map table is terminated by a zero, no space is remaining for next allocation or 4th partition is created in MBR format. If the specified size is larger than remaining space on the drive, the partition is clipped at the size of remaining space.</p>
<p>By default, partitions are created in MBR format. It can create upto four primary partitions on a drive. GPT format is used to create the partitions when 64-bit LBA is enabled (<tt>FF_LBA64 = 1</tt>) and the drive size is equal to or larger than <tt><a href="config.html#fs_gptmin">FF_MIN_GPT</a></tt> sectors. It can create over ten partitions on a drive.</p>
</div>

<div class="para comp">
<h4>QuickInfo</h4>
<p>Available when <tt><a href="config.html#fs_readonly">FF_FS_READOLNY</a> == 0</tt>, <tt><a href="config.html#use_mkfs">FF_USE_MKFS</a> == 1</tt> and <tt><a href="config.html#multi_partition">FF_MULTI_PARTITION</a> == 1</tt>.</p>
</div>

<div class="para use">
<h4>Example</h4>
<pre>
    <span class="c">/* Volume mapping table defined by user (required when FF_MULTI_PARTITION == 1) */</span>

    PARTITION VolToPart[FF_VOLUMES] = {
        {0, 1},    <span class="c">/* "0:" ==> Physical drive 0, 1st partition */</span>
        {0, 2},    <span class="c">/* "1:" ==> Physical drive 0, 2nd partition */</span>
        {1, 0}     <span class="c">/* "2:" ==> Physical drive 1, auto detection */</span>
    };
</pre>
<pre>
    <span class="c">/* Initialize a brand-new disk drive mapped to physical drive 0 */</span>

    BYTE work[FF_MAX_SS];         <span class="c">/* Working buffer */</span>
    LBA_t plist[] = {50, 50, 0};  <span class="c">/* Divide the drive into two partitions */</span>
                 <span class="c">/* {0x10000000, 100}; 256M sectors for 1st partition and left all for 2nd partition */</span>
                 <span class="c">/* {20, 20, 20, 0}; 20% for 3 partitions each and remaing space is left not allocated */</span>

    <em>f_fdisk</em>(0, plist, work);                    <span class="c">/* Divide physical drive 0 */</span>

    f_mkfs("0:", 0, work, sizeof work); <span class="c">/* Create FAT volume on the logical drive 0 */</span>
    f_mkfs("1:", 0, work, sizeof work); <span class="c">/* Create FAT volume on the logical drive 1 */</span>

</pre>
</div>

<div class="para ref">
<h4>See Also</h4>
<p><a href="filename.html#vol">Volume management</a>, <a href="mkfs.html"><tt>f_mkfs</tt></a></p>
</div>

<p class="foot"><a href="../00index_e.html">Return</a></p>
</body>
</html>
